package com.ruoyi.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.contract.domain.Contract;
import com.ruoyi.contract.domain.contractVo.ContractAllPartyVo;
import com.ruoyi.contract.domain.contractVo.RewriteProjectContractVo;
import com.ruoyi.contract.domain.contractVo.SelectedContractsVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.contract.domain.ContractProject;
import com.ruoyi.contract.service.IContractProjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目Controller
 * 
 * @author ruoyi
 * @date 2024-10-18
 */
@RestController
@RequestMapping("/contract/ContractProject")
public class ContractProjectController extends BaseController
{
    @Autowired
    private IContractProjectService contractProjectService;

    /**
     * 查询项目列表
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractProject:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractProject contractProject)
    {
        startPage();
        List<ContractProject> list = contractProjectService.selectContractProjectList(contractProject);
        return getDataTable(list);
    }

    /**
     * 导出项目列表
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractProject:export')")
    @Log(title = "项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractProject contractProject)
    {
        List<ContractProject> list = contractProjectService.selectContractProjectList(contractProject);
        ExcelUtil<ContractProject> util = new ExcelUtil<ContractProject>(ContractProject.class);
        util.exportExcel(response, list, "项目数据");
    }

    /**
     * 获取项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractProject:query')")
    @GetMapping(value = "/{contractProjectId}")
    public AjaxResult getInfo(@PathVariable("contractProjectId") Long contractProjectId)
    {
        return success(contractProjectService.selectContractProjectByContractProjectId(contractProjectId));
    }

    /**
     * 新增项目
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractProject:add')")
    @Log(title = "项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RewriteProjectContractVo rewriteProjectContractVo)
    {
        return toAjax(contractProjectService.insertContractProject(rewriteProjectContractVo));
    }

    /**
     * 修改项目
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractProject:edit')")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RewriteProjectContractVo rewriteProjectContractVo)
    {
        return toAjax(contractProjectService.updateContractProject(rewriteProjectContractVo));
    }

    /**
     * 删除项目
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractProject:remove')")
    @Log(title = "项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractProjectIds}")
    public AjaxResult remove(@PathVariable Long[] contractProjectIds)
    {
        return toAjax(contractProjectService.deleteContractProjectByContractProjectIds(contractProjectIds));
    }

    /**
     * 查询项目对应所属公司未选择过的合同
     */
    @PreAuthorize("@ss.hasPermi('contract:ContractProject:list')")
    @GetMapping("/unselectedContracts")
    public TableDataInfo unselectedContracts(SelectedContractsVo selectedContracts)
    {
        List<ContractAllPartyVo> list = contractProjectService.unselectedContracts(selectedContracts);
        return getDataTable(list);
    }
}
